﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace EpsiRisk.AffichageJeu
{
    public class ClassBouton : ClassZone
    {
        public event EventHandler Clicked;

        public string ButtonLabel;

        public bool Visible = true;

        private bool b_active;

        /// <summary>
        /// le bouton est il enfoncé
        /// </summary>
        public bool active
        {
            get { return b_active; }
            set
            {
                b_active = value;
                if (value)
                {
                    ButtonImage = ButtonActive;
                }
                else
                {
                    ButtonImage = ButtonInactive;
                }
            }
        }

        private Texture2D ButtonImage;

        public Texture2D ButtonActive;

        public Texture2D ButtonInactive;

        public Vector2 offset;

        /// <summary>
        /// Constructeur de  bouton actif/inactif
        /// </summary>
        /// <param name="spriteActive">sprite quand le bouton est actif</param>
        /// <param name="spriteInactive">sprite quand le bouton est inactif</param>
        public ClassBouton(Texture2D spriteActive, Texture2D spriteInactive)
        {
            ButtonActive = spriteActive;
            ButtonInactive = spriteInactive;
            active = false;
        }

        /// <summary>
        /// constructeur de Bouton standard
        /// </summary>
        /// <param name="sprite">Sprite du bouton</param>
        public ClassBouton(Texture2D sprite)
        {
            ButtonActive = sprite;
            ButtonInactive = sprite;
            active = false;
        }

        internal override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            if (Visible)
            {
                spriteBatch.Draw(ButtonImage, new Rectangle((int)(position.X + offset.X), (int)(position.Y + offset.Y), width, height), Color.White);//dessinne l'image du bouton ajustée a la taille definie 
            }
            spriteBatch.End();
        }

        internal override void clicXY(int x, int y)
        {
            if (Visible)
            {
                active = !active;
                if (Clicked != null)
                {
                    Clicked.Invoke(this, new EventArgs());
                }
            }
        }
    }
}
